#ifdef __linux__
#include <netinet/in.h>
#include <arpa/inet.h>
#endif // __linux__

#include <signal.h>

#include <iostream>
#include <frpc/frpc.h>
#include <protocol/frpc_msgio.h>
#include "workflow/WFServer.h"
#include "workflow/Workflow.h"
#include "workflow/WFFacilities.h"

#include <handler/handlers.h>
#include <handler/mysql_handler.h>
#include <task/frpc_task.h>
#include <cppbase/logging.h>
#include <cppbase/utility.h>

#include <handler/server.h>


static WFFacilities::WaitGroup wait_group(1);

void sig_handler(int signo)
{
	wait_group.done();
}
int main(int argc, char *argv[])
{
	AppGlobal::instance()->init("../sa_config.txt", "-");
	DBHandler::init_cache();
	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);
	Frpc::Server server(Frpc::get_default_router());
	if (server.start(AF_INET, 8080) == 0)
	{
		wait_group.wait();
		server.stop();
	}
	else
	{
		perror("server.start");
		exit(1);
	}
	return 0;
}